package com.company.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.company.project.common.aop.annotation.LogAnnotation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import com.company.project.common.utils.DataResult;

import com.company.project.entity.TWhbcsEntity;
import com.company.project.service.TWhbcsService;

import javax.annotation.Resource;


/**
 * 
 *
 * @author wenbin
 * @email *****@mail.com
 * @date 2023-11-08 19:49:28
 */
@Controller
@RequestMapping("/")
public class TWhbcsController {
    @Resource
    private TWhbcsService tWhbcsService;


    /**
    * 跳转到页面
    */
    @GetMapping("/index/tWhbcs")
    public String tWhbcs() {
        return "twhbcs/list";
        }

    @ApiOperation(value = "新增")
    @PostMapping("tWhbcs/add")
    @RequiresPermissions("tWhbcs:add")
    @ResponseBody
    public DataResult add(@RequestBody TWhbcsEntity tWhbcs){
        tWhbcsService.save(tWhbcs);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("tWhbcs/delete")
    @RequiresPermissions("tWhbcs:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        tWhbcsService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("tWhbcs/update")
    @RequiresPermissions("tWhbcs:update")
    @ResponseBody
    public DataResult update(@RequestBody TWhbcsEntity tWhbcs){
        tWhbcsService.updateById(tWhbcs);
        return DataResult.success();
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("tWhbcs/listByPage")
    @LogAnnotation(title = "未回拨操作", action = "查询分页数据")
    @RequiresPermissions("tWhbcs:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody TWhbcsEntity tWhbcs){
        Page page = new Page(tWhbcs.getPage(), tWhbcs.getLimit());
        LambdaQueryWrapper<TWhbcsEntity> queryWrapper = Wrappers.lambdaQuery();
        //查询条件示例
        //queryWrapper.eq(TWhbcsEntity::getId, tWhbcs.getId());
        IPage<TWhbcsEntity> iPage = tWhbcsService.getPageList(page, tWhbcs);
        return DataResult.success(iPage);
    }

}
